package example.chapter12.sort;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class SortTagAction extends ActionSupport{
	private List<String> fruits;
	
	public String execute() throws Exception{
		fruits = new ArrayList<String>();
		fruits.add("grape");
		fruits.add("banana");
		fruits.add("apple");
		fruits.add("strawberry");
		fruits.add("orange");
		return SUCCESS;
	}
	
	public Comparator getMyComparator(){
		return new Comparator(){
			public int compare(Object o1, Object o2){
				String s1 = (String) o1;
				String s2 = (String) o2;
				return s1.compareTo(s2);
			}
		};
	}

	public List<String> getFruits() {
		return fruits;
	}

	public void setFruits(List<String> fruits) {
		this.fruits = fruits;
	}
	
}
